package HW4;

import java.io.*;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CheckClinet {
    public static void main(String[] args){
        //输入账号密码，初始化usermessage是成功的
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入账户名称:");
        String name = sc.nextLine();
        System.out.println("请输入账户密码:");
        String passWord = sc.nextLine();
        String st = "success";

        //把多个对象放到一个集合中
        List<UserMessage> li = new ArrayList<>();
        UserMessage um = new UserMessage(st,new Users(name,passWord));
        li.add(um);

        //输入输出流
        Socket s = null;
        ObjectOutputStream oos = null;
        InputStream is = null;
        DataInputStream dis = null;
        try {
            s = new Socket("localhost",8888);
            //将对象输出到服务器
            oos = new ObjectOutputStream(s.getOutputStream());
            oos.writeObject(li);

            //接收服务器信息
            is = s.getInputStream();
            dis = new DataInputStream(is);
            System.out.print(dis.readUTF());

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(null!=s){
                try {
                    s.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(null!=oos){
                try {
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                dis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }
}
